import { getPackageJSON, resolvePackagePath, getBaseRollupPlugins } from './utils';
import generatePackageJson from 'rollup-plugin-generate-package-json';

const { name, module } = getPackageJSON('react');
const pkgPath = resolvePackagePath(name);
const distPkgPath = resolvePackagePath(name, true);

export default [
	{
		input: `${pkgPath}/${module}`,
		output: {
			file: `${distPkgPath}/index.js`,
			name: 'React',
			format: 'umd',
		},
		plugins: [
			...getBaseRollupPlugins(),
			//  用于在打包产物中生成package.json
			generatePackageJson({
				// 哪个文件夹下的package.json
				inputFolder: pkgPath,
				// 哪个文件夹下创建package.json
				outputFolder: distPkgPath,
				// 输出的package.json包含哪些内容
				baseContents: ({ name, description, version }) => ({
					name,
					description,
					version,
					main: 'index.js',
				}),
			}),
		],
	},
	{
		input: `${pkgPath}/src/jsx.ts`,
		output: [
			{
				file: `${distPkgPath}/jsx-runtime.js`,
				name: 'jsx-runtime',
				format: 'umd',
			},
			{
				file: `${distPkgPath}/jsx-dev-runtime.js`,
				name: 'jsx-dev-runtime',
				format: 'umd',
			},
		],
		plugins: getBaseRollupPlugins(),
	},
];
